package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.MarketRole;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;

import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.roleBo.RoleBo2;
import com.cskaoyan.bean.roleBo.RolePermissionsBo;
import com.cskaoyan.bean.roleVo.RoleCreateVo;
import com.cskaoyan.bean.roleVo.RoleOptionVo;
import com.cskaoyan.bean.roleVo.RoleVo;
import com.cskaoyan.service.RoleService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.management.relation.Role;
import java.util.List;
import java.util.Map;

/**
 * @Author Austin Hsu
 * @Date 2022/9/9 22:16
 */
@RestController
@RequestMapping("admin/role")
public class RoleController {
    @Autowired
    RoleService roleService;

//------------------------------插入和测试-----------------------------------------------
    @RequestMapping("insert")                //用postman构造请求 扒数据进数据库
    public BaseRespVo insert(@RequestBody RoleBo2 bo){
        roleService.insert(bo);
        return BaseRespVo.ok3();
    }

    @RequestMapping("insert2")               //这里用String[]或者Arraylist<String>都能接收噢 很神奇
    public BaseRespVo insert2(@RequestBody String[] s){    //用postman构造list（数组）请求 测试TypeHandler是否生效(生效了)
        roleService.insert2(s);
        return BaseRespVo.ok3();
    }
//-------------------------------插入和测试------------------------------------------------

    @RequestMapping("list")
    public BaseRespVo list(MarketRole marketRole, BasePageInfo info){
        CommonData<MarketRole> data =roleService.query(marketRole,info);    //这个marketRole是用来接收name的
        return BaseRespVo.ok2(data);
    }

    @RequestMapping("create")
    public BaseRespVo create(@RequestBody MarketRole marketRole){          //！！没有写判重复的逻辑
        MarketRole data=roleService.create(marketRole);
        return BaseRespVo.ok2(data);
    }



    @GetMapping("permissions")
    public BaseRespVo permissions(Integer roleId){     //在url里的参数 没写requestbody进得来吗？
        RoleVo data=roleService.permissions(roleId);
        return BaseRespVo.ok2(data);
    }

    @PostMapping("permissions")
    public BaseRespVo permissions2(@RequestBody RolePermissionsBo rolePermissionsBo){
        RoleVo data=roleService.permissions2(rolePermissionsBo);  //其实用不到
        return BaseRespVo.ok3();
    }


    @RequestMapping("update")
    public BaseRespVo update(@RequestBody MarketRole marketRole){
        RoleCreateVo data=roleService.update(marketRole);
        return BaseRespVo.ok2(data);}


    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody MarketRole marketRole){
        RoleCreateVo data=roleService.delete(marketRole);
        return BaseRespVo.ok2(data);}


    @RequestMapping("options")
    public BaseRespVo options(){
        CommonData<RoleOptionVo> data =roleService.options();
        return BaseRespVo.ok2(data);
    }
}
